import request from '@/utils/request'
import { json2FormDate } from '@/utils/util';
import { forEach } from 'lodash';
import { CHECC_API_PROCESS } from '@/constants/proxy'


export const fetchList = (pagination = {}, data = {}) => {
  const { pageNum = 1, pageSize = 10, } = pagination;
  return request({
    url: CHECC_API_PROCESS + `/act/run/page`,
    method: 'post',
    params: {
      pageNum,
      pageSize,
    },
    data,
  })
}

// 删除记录
export const deleteRecord = params => request({
  url: CHECC_API_PROCESS + `/act/run/deleteProcIns`,
  method: 'delete',
  params,
})

export const stopFlow = (params) => {
  return request({
    url: CHECC_API_PROCESS + '/act/run/suspendOne',
    method: 'get',
    params,
  })
}

// 自由跳转
export const jumpFreeRequest = (params) => {
  const formData = new FormData();
  forEach(params, (value, label) => {
    formData.append(label, value);
  })
  return request({
    url: CHECC_API_PROCESS + '/act/task/jump',
    method: 'post',
    data: formData,
  })
}

//强制办结流程 
export function closeFlowRequest({ processInstanceId, comment }) {
  const data = json2FormDate({
    processInstanceId,
    comment,
    status: 1,
  })
  return request({
    url: CHECC_API_PROCESS + "/act/task/terminate",
    method: "post",
    data,
  })
}

//废弃流程
export function discardFlowRequest({ processInstanceId, comment }) {
  const data = json2FormDate({
    processInstanceId,
    comment,
    status: 2,
  })
  return request({
    url: CHECC_API_PROCESS + "/act/task/terminate",
    method: "post",
    data,
  })
}

// 获取流程状态字典项
export const requestFlowStatus = params => request({
  url: CHECC_API_PROCESS + `/enum-value/queryListByEnumId`,
  method: 'get',
  params,
})
